import java.io.*;

public class Copy {
  public static void main(String[] args) throws IOException {
    // 提示用户输入源文件名和输出文件名
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("请输入源文件名：");
    String sourceFileName = br.readLine();
    System.out.print("请输入输出文件名：");
    String targetFileName = br.readLine();

    // 加密源文件A并保存到加密文件B中
    try (
            BufferedInputStream input = new BufferedInputStream(new FileInputStream(sourceFileName));
            BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(targetFileName))
    ) {
      int r, numberOfBytesCopied = 0;
      while ((r = input.read()) != -1) {
        // 对每个字节加5并写入输出流
        output.write((byte)(r + 5));
        numberOfBytesCopied++;
      }
      System.out.println(numberOfBytesCopied + " 字节已加密并保存到文件 " + targetFileName);
    }

    // 读取加密文件B中的内容并解码
    try (
            BufferedInputStream input = new BufferedInputStream(new FileInputStream(targetFileName))
    ) {
      int r, numberOfBytesRead = 0;
      System.out.println("解码后的文件内容：" + targetFileName);
      while ((r = input.read()) != -1) {
        // 对每个字节减去5并输出
        System.out.print((char)(r - 5));
        numberOfBytesRead++;
      }
      System.out.println("\n已从文件 " + targetFileName + " 读取 " + numberOfBytesRead + " 字节");
    }
  }
}